<%@ page language="java" import="java.util.*,shop.dao.*,shop.entity.*" 	pageEncoding="utf-8"%>
<%
String userName = new String(request.getParameter("userName").getBytes("ISO-8859-1"),"utf-8");
String password = new String(request.getParameter("password").getBytes("ISO-8859-1"),"utf-8");
String password2 = new String(request.getParameter("password2").getBytes("ISO-8859-1"),"utf-8");
String phone = new String(request.getParameter("phone").getBytes("ISO-8859-1"),"utf-8");
String email = new String(request.getParameter("email").getBytes("ISO-8859-1"),"utf-8");

    Customer customer=new Customer();
	CustomerDao customerdao = new CustomerDao();
	AdminDao admindao = new AdminDao();

	
	if (userName == null || password == null || phone == null) {
		response.sendRedirect("../Create user.jsp");
	} else { 
	       if(customerdao.findname(userName)==false || admindao.findname(userName)==false){
            out
			.print("<script type='text/javascript'>alert('名字不可用。');history.go(-1);</script>");
     	}
     	else{
	      //注册操作
	    customer.setC_name(userName);
	    customer.setC_pass(password);
	    customer.setC_phone(phone);
	    customer.setC_email(email);
		int count = customerdao.insertUser(customer);
		if (count > 0) {
			out
			.print("<script type='text/javascript'>alert('注册成功，请登录。');location.replace('../login.jsp');</script>");
		} else {
			out
			.print("<script type='text/javascript'>alert('注册失败，请重新注册。');history.go(-1);</script>");
		}
		}
	}
%>
